<%-- 
    Document   : index
    Created on : 17/11/2011, 09:59:42 PM
    Author     : victor
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body> 
        <%
            String funcion = request.getParameter("funcion");
            String n = request.getParameter("n");
            String id =  (String) session.getAttribute("id");
            String x1 = request.getParameter("x1");
            String y1 = request.getParameter("y1");
            String result = "";
            if (funcion.equalsIgnoreCase("crear_partida")) {
                try {
                    Cliente.WService_Service service = new Cliente.WService_Service();
                    Cliente.WService port = service.getWServicePort();
                    // TODO initialize WS operation arguments here
                    // TODO process result here
                    result = port.crearPartida(n);
                    session.setAttribute("id", result);
                } catch (Exception ex) {
                    // TODO handle custom exceptions here
                }
            } else if (funcion.equalsIgnoreCase("finalizar_partida")) {
                try {
                    Cliente.WService_Service service = new Cliente.WService_Service();
                    Cliente.WService port = service.getWServicePort();
                    // TODO initialize WS operation arguments here
                    port.finalizarPartida(id);
                } catch (Exception ex) {
                    // TODO handle custom exceptions here
                }
            }
            else if (funcion.equalsIgnoreCase("final")) {
                try {
                    Cliente.WService_Service service = new Cliente.WService_Service();
                    Cliente.WService port = service.getWServicePort();
                    // TODO initialize WS operation arguments here
                    result = port.final_partida(id);
                } catch (Exception ex) {
                    // TODO handle custom exceptions here
                }
            }
            else if (funcion.equalsIgnoreCase("obtener_turno")) {
                try {
                    Cliente.WService_Service service = new Cliente.WService_Service();
                    Cliente.WService port = service.getWServicePort();
                    // TODO initialize WS operation arguments here
                    result = port.obtenerTurno(id);
                    if(result.equals("0"))
                        result= "<img src='imagenes/azul.png'>";
                    else
                        result="<img src='imagenes/rojo.png'>";
                } catch (Exception ex) {
                    // TODO handle custom exceptions here
                }
            }
            else if (funcion.equalsIgnoreCase("pasar")) {
                try {
                    Cliente.WService_Service service = new Cliente.WService_Service();
                    Cliente.WService port = service.getWServicePort();
                    // TODO initialize WS operation arguments here
                    port.pasar(id);
                } catch (Exception ex) {
                    // TODO handle custom exceptions here
                }
            }
            else if (funcion.equalsIgnoreCase("jugar")) {
                try {
                    Cliente.WService_Service service = new Cliente.WService_Service();
                    Cliente.WService port = service.getWServicePort();
                    // TODO initialize WS operation arguments here
                    result = ","+port.jugar(x1, y1, id);
                } catch (Exception ex) {
                    // TODO handle custom exceptions here
                }
            }
            else if (funcion.equalsIgnoreCase("logout")) {
                session.invalidate();
            }
            out.println(result);
        %>
    </body>
</html>
